package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;

import java.util.Iterator;

import static gunfire.GunfireMod.makeCardPath;

public class CrimsonFirescale extends CustomCard {

    public static final String ID = GunfireMod.makeID(CrimsonFirescale.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("CrimsonFirescale.png");
    private static final CardRarity RARITY = CardRarity.COMMON;
    private static final CardType TYPE = CardType.ATTACK;
    private static final CardTarget TARGET = CardTarget.ENEMY;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 1;

    public CrimsonFirescale() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseDamage = 9;
        this.cardsToPreview = new CrimsonFirescale2();

        this.tags.add(GunfireMod.ELEMENT_DAMAGE_CARD);
        this.damageType = this.damageTypeForTurn = GunfireMod.ELEMENT_DAMAGE;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeDamage(5);
            this.cardsToPreview.upgrade();
            this.rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            this.initializeDescription();
        }
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        this.addToBot(new DamageAction(m, new DamageInfo(p, damage, GunfireMod.ELEMENT_DAMAGE), AbstractGameAction.AttackEffect.FIRE));
        if(this.hasElementEffect(m)){
            AbstractCard c = new CrimsonFirescale2();
            if(this.upgraded){
                c.upgrade();
            }
            this.addToBot(new MakeTempCardInHandAction(c, 1, false));
        }
    }

    @Override
    public void triggerOnGlowCheck() {
        this.glowColor = AbstractCard.BLUE_BORDER_GLOW_COLOR.cpy();

        for (AbstractMonster m : AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (this.hasElementEffect(m)) {
                this.glowColor = AbstractCard.GOLD_BORDER_GLOW_COLOR.cpy();
                break;
            }
        }
    }

    private boolean hasElementEffect(AbstractMonster m){
        if (!m.isDeadOrEscaped()) {
            return m.hasPower("gunfire:BurningPower") || m.hasPower("gunfire:DecayPower") || m.hasPower("gunfire:ShockPower");
        }
        return false;
    }

    @Override
    public AbstractCard makeCopy() {
        return new CrimsonFirescale();
    }
}
